package org.cbg.until;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;

import com.tool.tcpimg.UIUtils;
import org.cbg.entity.Salegoods;
import org.cbg.panel.TraslationWantBuyDahuabiModelJpanel;
import org.cbg.panel.TraslationWantSentYijishangpinModelJpanel;
import org.come.until.cbgSrcollPanelUI;

public class TraslationTableYijishangpinUntil extends JPanel {

    TraslationWantBuyDahuabiModelJpanel traslationWantBuyDahuabiModelJpanel;

    public TraslationTableYijishangpinUntil() {
        // TODO Auto-generated constructor stub
    }

    /**
     * 自行生成结果展示
     * 
     * @param jScrollPane
//     * @param geshu
     *            多少条数据
     */
    public static JPanel TableModel(JScrollPane jScrollPane) {
        /** 表格 */
        JPanel jPanel = new JPanel();
        jPanel.setBackground(null);
        jPanel.setOpaque(false);
        jPanel.setBorder(null);
        jPanel.setLayout(null);
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(jPanel);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        jPanel.setPreferredSize(new Dimension(760, 0));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
        return jPanel;
    }

    /**
     * 根据查询条件查询结果展示
     * 
     * @param jScrollPane
     * @param salegoodsList
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Salegoods> salegoodsList) {
        /**
         * 表格
         */
        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        /**
         * 设置监听
         * 
         * @author Asus
         * 
         */
        class MListener extends MouseAdapter {
            @Override
            public void mouseEntered(MouseEvent e) {
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(UIUtils.COLOR_cbg5);
                btn.setOpaque(true);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel btn = (JPanel) e.getSource();
                btn.setBackground(null);
                btn.setOpaque(false);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

            }
        }
        for (int i = 0; i < salegoodsList.size(); i++) {
            TraslationWantSentYijishangpinModelJpanel traslationWantSentYijishangpinModelJpanel = new TraslationWantSentYijishangpinModelJpanel(
                    salegoodsList.get(i));
            traslationWantSentYijishangpinModelJpanel.setBounds(0, i * 62, 740, 60);
            MListener m = new MListener();
            traslationWantSentYijishangpinModelJpanel.addMouseListener(m);
            view.add(traslationWantSentYijishangpinModelJpanel);
        }
        view.setPreferredSize(new Dimension(760, 62 * salegoodsList.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

}
